package com.cheney.weiboo.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;

import com.cheney.weiboo.R;

public class TextUtil {
	
	public static Map<String,Integer> faceNameToDrawableId = new HashMap<String, Integer>();
	public static Map<String,String> drawableIdToFaceName = new HashMap<String, String>();
	
	static{
		drawableIdToFaceName.put("h000","调皮");
		drawableIdToFaceName.put("h001","呲牙");
		drawableIdToFaceName.put("h002","惊讶");
		drawableIdToFaceName.put("h003","难过");
		drawableIdToFaceName.put("h004","酷");
		drawableIdToFaceName.put("h005","冷汗");
		drawableIdToFaceName.put("h006","抓狂");
		drawableIdToFaceName.put("h007","吐");
		drawableIdToFaceName.put("h008","偷笑");
		drawableIdToFaceName.put("h009","可爱");
		drawableIdToFaceName.put("h010","白眼");
		drawableIdToFaceName.put("h011","傲慢");
		drawableIdToFaceName.put("h012","微笑");
		drawableIdToFaceName.put("h013","撇嘴");
		drawableIdToFaceName.put("h014","色");
		drawableIdToFaceName.put("h015","发呆");
		drawableIdToFaceName.put("h016","得意");
		drawableIdToFaceName.put("h017","流泪");
		drawableIdToFaceName.put("h018","害羞");
		drawableIdToFaceName.put("h019","嘘");
		drawableIdToFaceName.put("h020","困");
		
		drawableIdToFaceName.put("h021","尴尬");
		drawableIdToFaceName.put("h022","发怒");
		drawableIdToFaceName.put("h023","大哭");
		drawableIdToFaceName.put("h024","流汗");
		drawableIdToFaceName.put("h025","再见");
		drawableIdToFaceName.put("h026","敲打");
		drawableIdToFaceName.put("h027","擦汗");
		drawableIdToFaceName.put("h028","委屈");
		drawableIdToFaceName.put("h029","疑问");
		drawableIdToFaceName.put("h030","睡");
		drawableIdToFaceName.put("h031","亲亲");
		
		drawableIdToFaceName.put("h032","憨笑");
		drawableIdToFaceName.put("h033","调皮");
		drawableIdToFaceName.put("h034","阴险");
		drawableIdToFaceName.put("h035","奋斗");
		drawableIdToFaceName.put("h036","右哼哼");
		drawableIdToFaceName.put("h037","拥抱");
		drawableIdToFaceName.put("h038","坏笑");
		drawableIdToFaceName.put("h039","鄙视");
		drawableIdToFaceName.put("h040","晕");
		drawableIdToFaceName.put("h041","大兵");
		drawableIdToFaceName.put("h042","可怜");
		
		drawableIdToFaceName.put("h043","饥饿");
		drawableIdToFaceName.put("h044","咒骂");
		drawableIdToFaceName.put("h045","抠鼻");
		drawableIdToFaceName.put("h046","鼓掌");
		drawableIdToFaceName.put("h047","糗大了");
		drawableIdToFaceName.put("h048","左哼哼");
		drawableIdToFaceName.put("h049","哈欠");
		drawableIdToFaceName.put("h050","快哭了");
		drawableIdToFaceName.put("h051","吓");
		drawableIdToFaceName.put("h052","闭嘴");
		drawableIdToFaceName.put("h053","惊恐");
		
		drawableIdToFaceName.put("h054","折磨");
		drawableIdToFaceName.put("h055","示爱");
		drawableIdToFaceName.put("h056","爱心");
		drawableIdToFaceName.put("h057","心碎");
		drawableIdToFaceName.put("h058","蛋糕");
		drawableIdToFaceName.put("h059","闪电");
		drawableIdToFaceName.put("h060","炸弹");
		drawableIdToFaceName.put("h061","刀");
		drawableIdToFaceName.put("h062","足球");
		drawableIdToFaceName.put("h063","瓢虫");
		drawableIdToFaceName.put("h064","便便");
		
		drawableIdToFaceName.put("h065","咖啡");
		drawableIdToFaceName.put("h066","饭");
		drawableIdToFaceName.put("h067","猪");
		drawableIdToFaceName.put("h068","玫瑰");
		drawableIdToFaceName.put("h069","凋谢");
		drawableIdToFaceName.put("h070","月亮");
		drawableIdToFaceName.put("h071","太阳");
		drawableIdToFaceName.put("h072","礼物");
		drawableIdToFaceName.put("h073","强");
		drawableIdToFaceName.put("h074","弱");
		drawableIdToFaceName.put("h075","握手");
		
		drawableIdToFaceName.put("h076","胜利");
		drawableIdToFaceName.put("h077","抱拳");
		drawableIdToFaceName.put("h078","勾引");
		drawableIdToFaceName.put("h079","拳头");
		drawableIdToFaceName.put("h080","差劲");
		drawableIdToFaceName.put("h081","爱你");
		drawableIdToFaceName.put("h082","NO");
		drawableIdToFaceName.put("h083","OK");
		drawableIdToFaceName.put("h084","爱情");
		drawableIdToFaceName.put("h085","飞吻");
		drawableIdToFaceName.put("h086","跳跳");
		
		drawableIdToFaceName.put("h087","发抖");
		drawableIdToFaceName.put("h088","怄火");
		drawableIdToFaceName.put("h089","转圈");
		drawableIdToFaceName.put("h090","磕头");
		drawableIdToFaceName.put("h091","回头");
		drawableIdToFaceName.put("h092","跳绳");
		drawableIdToFaceName.put("h093","挥手");
		drawableIdToFaceName.put("h094","激动");
		drawableIdToFaceName.put("h095","街舞");
		drawableIdToFaceName.put("h096","献吻");
		drawableIdToFaceName.put("h097","左太极");
		
		drawableIdToFaceName.put("h098","右太极");
		drawableIdToFaceName.put("h099","菜刀");
		drawableIdToFaceName.put("h100","西瓜");
		drawableIdToFaceName.put("h101","啤酒");
		drawableIdToFaceName.put("h102","骷髅");
		drawableIdToFaceName.put("h103","篮球");
		drawableIdToFaceName.put("h104","乒乓");
	}
	
	
	public static SpannableString decorateFaceInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		Drawable drawable = null;
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				drawable = resources.getDrawable(faceNameToDrawableId.get(map.get("faceName")));
				drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
				ImageSpan span = new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE);
				spannable.setSpan(span, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
	public static SpannableString decorateVipInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		Drawable drawable = null;
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				drawable = resources.getDrawable(R.drawable.vip);
				drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
				ImageSpan span = new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE);
				spannable.setSpan(span, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
	
	public static SpannableString decorateTopicInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		Drawable drawable = null;
		CharacterStyle foregroundColorSpan=new ForegroundColorSpan(Color.argb(255, 33, 92, 110));
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				spannable.setSpan(foregroundColorSpan, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
	
	public static SpannableString decorateRefersInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		Drawable drawable = null;
		CharacterStyle foregroundColorSpan=new ForegroundColorSpan(Color.argb(255, 33, 92, 110));
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				spannable.setSpan(foregroundColorSpan, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
}
